package flc.ast.adapter;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyVoiceBean;
import flc.ast.bean.TransferRecordBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.view.container.StkRecycleView;

public class TransferRecordAdapter extends StkProviderMultiAdapter<TransferRecordBean> {

    public TransferRecordAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(40));
        addItemProvider(new TransferRecordProvider());
    }

    private boolean isEdit = false;

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class TransferRecordProvider extends BaseItemProvider<TransferRecordBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_transfer_record;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, TransferRecordBean bean) {
            baseViewHolder.setText(R.id.tvTransferRecordItemTime, bean.getTime());
            StkRecycleView recycleView;
            RecordKindAdapter kindAdapter = new RecordKindAdapter();
            kindAdapter.setEdit(isEdit);
            switch (bean.getType()) {
                case 1:
                case 2:
                    baseViewHolder.getView(R.id.rvTransferRecordItemImgList).setVisibility(View.VISIBLE);
                    baseViewHolder.getView(R.id.rvTransferRecordItemList).setVisibility(View.GONE);
                    recycleView = baseViewHolder.getView(R.id.rvTransferRecordItemImgList);
                    recycleView.setLayoutManager(new GridLayoutManager(getContext(), 3));
                    recycleView.setAdapter(kindAdapter);
                    kindAdapter.setList(bean.getList());
                    break;
                case 3:
                case 4:
                case 5:
                    baseViewHolder.getView(R.id.rvTransferRecordItemImgList).setVisibility(View.GONE);
                    baseViewHolder.getView(R.id.rvTransferRecordItemList).setVisibility(View.VISIBLE);
                    recycleView = baseViewHolder.getView(R.id.rvTransferRecordItemList);
                    recycleView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
                    recycleView.setAdapter(kindAdapter);
                    kindAdapter.setList(bean.getList());
                    break;
            }
            kindAdapter.setOnItemClickListener(getOnItemClickListener());
//            kindAdapter.setOnItemClickListener(new OnItemClickListener() {
//                @Override
//                public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
//                    if (kindAdapter.getItem(position).isSelected()) {
//                        kindAdapter.getItem(position).setSelected(false);
//                    } else {
//                        kindAdapter.getItem(position).setSelected(true);
//                    }
//                }
//            });
        }
    }
}
